package com.tfriend.scheduler.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import org.springframework.web.servlet.view.RedirectView;

import com.tfriend.scheduler.comp.schedulerData;
import com.tfriend.scheduler.comp.schedulerService;

@Controller
public class schedulerController extends MultiActionController{
	
	@Autowired
	private schedulerService schedulerService;
	
	@RequestMapping("/schedulerData.do")
	public ModelAndView schedulerUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
		request.setCharacterEncoding("UTF-8");
		int no = Integer.parseInt(request.getParameter("no"));
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		
		schedulerData data = new schedulerData();
		data.setNo(no);
		data.setTitle(title);
		data.setContent(content);
		
		schedulerService.upateContent(data);
		
		return new ModelAndView(new RedirectView("boardList.do"));
	}	
	@RequestMapping("/schedulerData.do")
	public ModelAndView schedulerData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		request.setCharacterEncoding("UTF-8");
		StringBuffer data = schedulerService.getSchedulerData();
		
		return new ModelAndView("scheduler/schedulerData").addObject("data", data);
	}
		
}
